
# def sift(li,low,high):
#     """
#     :param li:   列表
#     :param low:  堆的根节点
#     :param high:  堆的最后一个叶子节点
#     :return:
#     """
#     i = low
#     j = i * 2 + 1
#     tmp = li[low]
#     while j <= high: # j节点有数
#         if j + 1 <= high and li[j] < li[j+1]: # 右孩子节点和左孩子节点比较
#             j = j + 1
#         if tmp < li[j]: # 判断两个数大小 决定是否交换
#             li[i] = li[j]
#             i = j
#             j = i * 2 + 1
#         else:
#             li[i] = tmp
#             break
#     else:
#         li[i] = tmp
#
# def heap_sort(li):
#     n = len(li)
#     for i in range((n-2)//2,-1,-1):
#         sift(li,i,n-1)
#     # 建堆完成
#     for i in range(n-1,-1,-1):
#         li[0],li[i] = li[i],li[0]
#         sift(li,0,i-1)
#
#
# li = [1,2,3,5,7,4,6,8,0]
# heap_sort(li)
# print(li)


# 内置模块
import heapq # q->queue 优先队列

li = [1,2,3,5,7,4,6,8,0]
heapq.heapify(li)  # 默认建堆为小根堆
print(li)
for i in range(len(li)):
    print(heapq.heappop(li))